<?php

namespace App\Http\Controllers\Api;

use Validator;
use App\Logic\SchoolLogic;
use App\Models\School;
use App\Models\Classes;
use Illuminate\Http\Request;


class SchoolController extends ApiController
{
    /**
     * 获取店铺列表信息
     */
    public function index(Request $request)
    {
        $where[] = ['status','=',2];
        if ($request->input('nameLike')) {
            $where[] = ['school_name', 'like', "%{$request->input('nameLike')}%"];
        }
        return SchoolLogic::getSchoolList($where);
    }
    
    public function detail(Request $request)
    {
        $validator = Validator::make($request->all(),
            [
                'id' => 'required'
            ],
            [
                'id.required' => 'id is required'
            ]
            );
        
        if ($validator->fails()) {
            return $this->failed($validator->errors(), 401);
        }
   
        $result = School::getSchoolInfoByID($request->id);
        if ($result) {
            return $result;
        } else {
            return $this->failed('This Store is not exists', 401);
        }
    }
    
    
}
